package com.company.OfferGuide;

public class 不相交的线 {

    public int maxUncrossedLines(int[] A, int[] B) {
        int m = A.length,n = B.length;

        int[][] dp = new int[m + 1][n + 1];


        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int d1 = A[i];
                int d2 = B[j];
                if (d1 == d2) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = Math.max(dp[i][j + 1], dp[i + 1][j]);
                }
            }
        }


        return dp[m][n];
    }

}
